# @Name:sendEmail
# @author:22326
# @Description:
# @DATE:2022/7/1 15:17
# @Modified By:

import http.client
import urllib

host = "106.ihuyi.com"
sms_send_uri = "/webservice/sms.php?method=Submit"

# 用户名是登录用户中心->验证码短信->产品总览->APIID
account = "C98159604"
# 密码 查看密码请登录用户中心->验证码短信->产品总览->APIKEY
password = "d9204f7e3b062a123ad72b15d8730f6c"


def send_sms(code, mobile):
   
    text = "您的验证码是：%s。请不要把验证码泄露给其他人。"%code
    
    params = urllib.parse.urlencode({'account': account, 'password': password, 'content': text, 'mobile': mobile, 'format': 'json'})
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    
    conn = http.client.HTTPConnection(host, port=80, timeout=30)
    
    conn.request("POST", sms_send_uri, params, headers)
    response = conn.getresponse()
    # 将数据解析成utf-8格式
    response_str = response.read().decode("utf-8")
    conn.close()
    
    return response_str


